import { createApp } from 'vue';
import { createPinia } from 'pinia';
import * as ElementPlusIconsVue from '@element-plus/icons-vue';
import App from './App.vue';
import router from './router';
import { usePermissStore } from './store/permiss';
import 'element-plus/dist/index.css';
import './assets/css/icon.css';
import axios from "axios";
import { config } from 'md-editor-v3/lib/MdEditor/config';

 axios.defaults.baseURL = "http://localhost:6060/";

const app = createApp(App);
app.use(createPinia());
app.use(router);

// app.config.globalProperties.$axios = axios;


// 注册elementplus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
// 自定义权限指令
// const permiss = usePermissStore();
// app.directive('permiss', {
//     mounted(el, binding) {
//         // if (!permiss.key.includes(String(binding.value))) {
//             el['hidden'] = true;
//         // }
//     },
// });

//配置Axios
axios.interceptors.request.use((config) => {
    
    config.baseURL = "http://localhost:6060/"
    //判断是否为登录请求
    if(config.url === "/auth/login"){
        //不需要加token
        return config
    }else{
        const token = JSON.parse(localStorage.getItem("token"));
        console.log(token)
        //其他请求需要在请求头中添加token
        config.headers.common["token"] = token;
    }
    return config;

});

//将Axios 实例添加到 Vue实例的全局属性
app.config.globalProperties.$axios = axios;
app.mount('#app');
